import numpy as n
from enthought.traits.api \
    import HasTraits, Array, Range, Float, Enum, on_trait_change, Property
from enthought.traits.ui.api import View, Item
from enthought.chaco.chaco_plot_editor import ChacoPlotItem
# TODO: use this instead
from enthought.enable.component_editor import ComponentEditor
# TODO: retain all data here, let user select range, channels (N channels)
class Oscilloscope(HasTraits):
    sample_rate=Float(256)
    samples = Array
    time = Property(Array, depends_on=['samples', 'sample_rate'])
    amplitude = Array
    frequency = Property(Array, depends_on=['amplitude', 'sample_rate'])
    plot_type=Enum("line", "scatter")
    traits_view = View(
        ChacoPlotItem("time", "samples",
            type_trait="plot_type",
            resizable=True,
            x_label="s",
            y_label="uV",
            x_auto=True,
            y_bounds=(-300,300),
            y_auto=False,
            color="blue",
            bgcolor="white",
            border_visible=True,
            border_width=1,
            title="Channel 1",
            padding_bg_color="lightgray"),
        ChacoPlotItem("frequency", "amplitude",
            type_trait="plot_type",
            resizable=True,
            x_label="?",
            y_label="?",
            x_auto=True,
            y_auto=False,
            y_bounds=(0,15000),
            color="blue",
            bgcolor="white",
            border_visible=True,
            border_width=1,
            title="FFT Channel 1",
            padding_bg_color="lightgray"),
        Item(name='plot_type'),
        resizable=True,
        title="pyofeedback",
        width=500, height=600)
    def _samples_default(self):
        return n.zeros(0)
    def _get_time(self):
        return n.arange(self.samples.size)#/self.sample_rate
    def _amplitude_default(self):
        return n.zeros(0)
    def _get_frequency(self):
        return n.arange(self.amplitude.size)#/self.sample_rate
